//
//  Person.m
//  05-HomeWork
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person
- (NSString *)description {
    return [NSString stringWithFormat:@"name : %@ age : %ld sex : %@", _name, _age, _sex];
}
// 对名字升序比较
- (NSComparisonResult)compareWithName: (Person *)otherPerson {
    return [self.name compare:otherPerson.name];
}
// 对年龄升序比较
- (NSComparisonResult)compareWithAge: (Person *)otherPerson {
    if (self.age > otherPerson.age) {
        return NSOrderedDescending;
    } else if (self.age < otherPerson.age) {
        return NSOrderedAscending;
    } else {
        return NSOrderedSame;
    }
}
// 对性别进行排序
- (NSComparisonResult)compareWithSex: (Person *)otherPerson {
    return [self.sex compare:otherPerson.sex];
}

@end
